using Microsoft.AspNetCore.Mvc;
using newApi.Services;
using newApi.Models;

namespace newApi.Controllers;
[ApiController]
[Route("api/[controller]")]
public class ChanelController : ControllerBase
{
    private readonly ChanelsService _chanelsService;

    public ChanelController(ChanelsService chanelsService) =>
        _chanelsService = chanelsService;

    //  [HttpGet]
    // public async Task<List<Chanel>> Get() =>
    //     await _chanelsService.GetAsync();
    [HttpGet]
    public async Task<IActionResult> Get()
    {
        List<string> result = new List<string>();
        var Chanels = await _chanelsService.GetAsync();
        foreach (var c in Chanels)
        {
            result.Add(c.Title);
        }
        return Ok(result);
    }


    [HttpPost]
    public async Task<IActionResult> Post(Chanel newChanel)
    {
        await _chanelsService.CreateChanel(newChanel);
        return CreatedAtAction(nameof(Get), new { id = newChanel.Id }, newChanel); ;
    }
    
}